
import 'package:bike_ride/common/util/hysize_fit.dart';
import 'package:bike_ride/generated/l10n.dart';
import 'package:flutter/material.dart';

class ErrorInfoWidget extends StatelessWidget {
  final Object? errorMsg;
  final double? height;
  final VoidCallback retry;
  final bool? hidePic;//是否隐藏图片
  final bool? hideRetry;//是否隐藏重试

  const ErrorInfoWidget({Key? key, this.errorMsg, this.height, required this.retry, this.hidePic = false, this.hideRetry = false})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    String tipsMsg = '';
    if(errorMsg!=null && errorMsg != 'null'){
      tipsMsg = '${S.current.failedLoad}:$errorMsg';
    }else{
      tipsMsg = S.current.noData;
    }
    return SizedBox(
      height: height ?? MediaQuery.of(context).size.height * 0.6,
      child: GestureDetector(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            const Expanded(
              flex: 2,
              child: SizedBox(),
            ),
            if(!hidePic!)
              SizedBox(
                width: 460.rpx,
                child: const Image(
                    image: AssetImage('assets/images/empty.png')),
              ),
            SizedBox(height: 10.rpx),
            Text(
              tipsMsg,
              style: TextStyle(
                fontSize: 28.rpx,
                color: Colors.black.withOpacity(0.45),
                fontWeight: FontWeight.w500,
              ),
            ),
            if(!hideRetry!)
              TextButton(onPressed: retry, child: Text(S.current.retry)),
            const Expanded(
              flex: 3,
              child: SizedBox(),
            ),
          ],
        ),
        onTap: ()=>retry(),
      ),
    );
  }
}
